<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/res/back/css/base.css" rel="stylesheet" type="text/css" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/bootstrap3/bootstrap.autocomplete.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script src="/res/third/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/res/third/easyUI/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script type="text/javascript">
	function sosuo() {
		var lpath = location.pathname;
		if ($("#so_companyname").val() == "") {
			$("#so_companyname").attr('real-value', '');
		}
		var company_id = $("#so_companyname").attr('real-value');
		$("#so_companyid").val(company_id);

		$("#soform").attr("action", lpath + "?pageNo=" + 1);
		$("#soform").submit();
	}
</script>
<style type="text/css">
</style>

</head>

<body>
	<div class="panel panel-info panel-content">
		<div class="panel-heading">
			<button style="float: right" type="button" onclick="addcontract()" class="btn btn-info">
				<span class="glyphicon glyphicon-plus"></span>
				&nbsp;新增合同模板
			</button>

			<form id="soform" method="post">
				<table>
					<tr>
						<td class="w80" style="padding-top: 5px">
							<label for="companyname" class="center-block">公司名称：</label>
						</td>
						<td class="w200 ">
							<input type="text" class="form-control" name="so_companyname" value="${so_companyname!}" id="so_companyname" placeholder="企业名称" data-options="" real-value="${so_companyid!}" autocomplete="off">
							<input type="hidden" name="so_companyid" id="so_companyid" value="${so_companyid!}">
						</td>
						<td style="padding-left: 10px">
							<div class="input-group">
								<span class="input-group-btn">
									<button class="btn btn-default" type="button" onclick="sosuo()">搜索</button>
								</span>
							</div>
						</td>
					</tr>
				</table>
			</form>
		</div>
		<table class="table table-hover table-bordered table-striped table-condensed">
			<thead>
				<tr>
					<th>序号</th>
					<th>合同名称</th>
					<th>公司名称</th>
					<th>合同类型</th>
					<th>合同状态</th>
					<th>是否默认模板</th>
					<th>操作</th>
				</tr>
			</thead>
			[#list pagination.list as contract ]
			<tr>
				<td align="center">${contract_index + 1}</td>
				<td align="center">${contract.name!}</td>
				<td align="center">${contract.company.companyName!}</td>
				<td align="center">[#list dictionarys as dictionary] [#if contract.type??][#if (contract.type?substring(0))==dictionary.code]${dictionary.name!}[/#if][/#if] [/#list]</td>
				<td align="center">[#if contract.state??][#if contract.state==1]启用[#elseif contract.state==0]禁用[#else][/#if][/#if]</td>
				<td align="center">[#if contract.ifDefault??][#if contract.ifDefault==1]是[#elseif contract.ifDefault==0]否[#else][/#if][/#if]</td>
				<td align="center">
					<button type="button" class="btn btn-danger btn-xs delbtn" onclick="editcontract('${contract.id}')">编辑</button>
					<button type="button" class="btn btn-danger btn-xs delbtn" onclick="del('${contract.id}')">删除</button>
				</td>
			</tr>
			[/#list]
		</table>
		<div class="panel-footer">[@fenye p = pagination form = 'infoForm' /]</div>
	</div>



</body>
</html>
<script type="text/javascript">
	$(function() {
		$('#so_companyname').autocomplete({
			source : function(query, process) {
				var matchCount = 6; //this.options.items;返回结果集最大数量
				$.post("/company/autocustomer.do", {
					"query" : query,
					"matchCount" : matchCount
				}, function(respData) {
					var json = JSON.parse(respData);
					return process(json.obj);
				});
			},
			formatItem : function(items) {
				return items["companyName"];
			},
			setValue : function(items) {
				return {
					'data-value' : items["companyName"],
					'real-value' : items["id"]
				};
			}
		});
	});
	//删除
	function del(id) {//弹出警告框判断是否删除
		if (confirm('是否确认删除')) {
			$.ajax({
				url : '/contract/ajax_del.do',
				type : 'get',
				dataType : 'json',
				data : {
					id : id
				},
				beforeSend : function() {
					art.dialog.tips("删除中...");
				},
				success : function(data) {
					if (data.success) {
						location.reload();
					} else {
						error_msg(data.msg, function() {
							location.reload();
						});
					}
				}
			});
		}
	}

	//跳转新增页面
	function addcontract() {
		top.addTempTab("/contract/v_add.do");
	}
	//跳转编辑页面
	function editcontract(id) {
		top.addTempTab("/contract/v_edit.do?so_id=" + id);
	}
</script>
